﻿<Page x:Class="OFX.Aggregator.WpfApplication.AccountTypeSelectionPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:OFX.Aggregator.WpfApplication"
    Title="New Account - Type"
    x:Name="theAccountTypeSelectionPage" ShowsNavigationUI="True"
    Margin="3" Loaded="theAccountTypeSelectionPage_Loaded">

    <Page.Resources>
        <DataTemplate x:Key="statementSourceTemplate" DataType="OFX.Aggregator.Infrastructure.StatementSourceTemplate">
            <TextBlock x:Name="DisplayName" Foreground="Black" FontSize="14" 
                       Text="{Binding Mode=OneWay, Path=DisplayName}"
                       Margin="3"/>

            <DataTemplate.Triggers>
                <DataTrigger Binding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type ListBoxItem}}, Path=IsSelected}" Value="True">
                    <DataTrigger.EnterActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ParallelTimeline>
                                    <DoubleAnimation To="24" Duration="0:0:0.05"
                                                             Storyboard.TargetName="DisplayName"
                                                             Storyboard.TargetProperty="FontSize"
                                                             AccelerationRatio="0.9"/>
                                </ParallelTimeline>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.EnterActions>

                    <DataTrigger.ExitActions>
                        <BeginStoryboard>
                            <Storyboard>
                                <ParallelTimeline>
                                    <DoubleAnimation To="14" Duration="0:0:0.05"
                                                             Storyboard.TargetName="DisplayName"
                                                             Storyboard.TargetProperty="FontSize"
                                                             AccelerationRatio="0.9"/>
                                </ParallelTimeline>
                            </Storyboard>
                        </BeginStoryboard>
                    </DataTrigger.ExitActions>

                    <Setter TargetName="DisplayName" Property="FontWeight" Value="UltraBold"/>
                    <Setter TargetName="DisplayName" Property="Foreground" Value="Blue"/>
                    <Setter TargetName="DisplayName" Property="Background" Value="{StaticResource SelectedItemBrush}" />
                </DataTrigger>
            </DataTemplate.Triggers>
        </DataTemplate>

        <Style x:Key="ListBoxItemContainerStyle"
				 TargetType="{x:Type ListBoxItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border Name="Bd"
									Background="{TemplateBinding Background}"
									BorderBrush="{TemplateBinding BorderBrush}"
									BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="3" 
									Padding="{TemplateBinding Padding}"
                                    Margin="{TemplateBinding Margin}" 
									SnapsToDevicePixels="true">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
															VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
															SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected"
										 Value="true">
                                <Setter TargetName="Bd"
											Property="Background"
											Value="{StaticResource SelectedItemBrush}"/>
                                <Setter Property="Foreground"
											Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"/>
                                <Setter Property="Cursor" Value="Hand"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected"
													 Value="true"/>
                                    <Condition Property="Selector.IsSelectionActive"
													 Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter TargetName="Bd"
											Property="Background"
											Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                <Setter Property="Foreground"
											Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
                            </MultiTrigger>
                            <Trigger Property="IsEnabled"
										 Value="false">
                                <Setter Property="Foreground"
											Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </Page.Resources>

    <Page.CommandBindings>
        <CommandBinding Command="local:AccountTypeSelectionPage.StatementSourceTemplate_CreateStatementSource" CanExecute="CanCreateStatementSource" Executed="CreateStatementSource"/>
    </Page.CommandBindings>

    <StackPanel Height="Auto">
        <Label Height="Auto" Name="labelAccountType" Width="Auto" Margin="3">Which kind of account do you wish to setup?</Label>
        <Border CornerRadius="3" BorderThickness="1" BorderBrush="Black" Background="Transparent">
            <Grid>
                <Rectangle Fill="White" Opacity="0.5" />
                <ListBox Name="listBoxStatementSourceTemplates" Height="Auto" MinHeight="100"  Width="Auto"
                         Margin="3"
                         ItemsSource="{Binding ElementName=theAccountTypeSelectionPage, Path=StatementSourceTemplates}"
                         ItemTemplate="{StaticResource statementSourceTemplate}"
                         Background="Transparent"
                         ItemContainerStyle="{StaticResource ListBoxItemContainerStyle}"
                         IsSynchronizedWithCurrentItem="True" BorderThickness="0" />
            </Grid>
        </Border>
        <Button
            Command="local:AccountTypeSelectionPage.StatementSourceTemplate_CreateStatementSource"
            CommandParameter="{Binding ElementName=listBoxStatementSourceTemplates, Path=SelectedItem, Mode=OneWay}"
            Height="Auto" Width="Auto"
            HorizontalAlignment="Right" Margin="3" Padding="3"
            FontWeight="Bold" IsDefault="True" Content="Create Account"/>
    </StackPanel>
</Page>
